# from wand.image import Image
#
# with Image(filename='123.pdf') as pdf:
#     with pdf.convert('jpeg') as image:
#         image.resize(width, height)
#         image.save(filename='result.jpeg')

# import ghostscript
#
# def pdf2jpeg(pdf_input_path, jpeg_output_path="1.jpg"):
#     args = ["pdf2jpeg", # actual value doesn't matter
#             "-dNOPAUSE",
#             "-sDEVICE=jpeg",
#             "-r144",
#             "-sOutputFile=" + jpeg_output_path,
#             pdf_input_path]
#     x = ghostscript.Ghostscript("123.pdf")
#     x.exit()
#
#
# pdf2jpeg("123.pdf")

# openoffice -accept="socket,host=localhost,port=2002;urp;StarOffice.ServiceManager"
# /usr/bin/openoffice -accept="socket,host=localhost,port=2002;urp;StarOffice.ServiceManager" -norestore -nofirstwizard -nologo -headless

import uno

local = uno.getComponentContext()

resolver = local.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", local)

context = resolver.resolve("uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext")

desktop = context.ServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", context)

document = desktop.getCurrentComponent()

document = desktop.loadComponentFromURL("file:///home/lucas/myfile.odt" ,"_blank", 0, ())

# document = desktop.loadComponentFromURL("file:///c:"+filepath+".odt" ,"_blank", 0, ())

# document.store() # save

# document.storeAsURL("file:///home/lucas/myfile2.odt",()) # Save file as

# document.dispose() # exit

from com.sun.star.beans import PropertyValue
property = (PropertyValue( "FilterName" , 0, "writer_pdf_Export" , 0 ),)

document.storeToURL("file:///home/lucas/myfile2.pdf",property)


